package com.alertdroid2;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Point;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.Projection;

public class MyOverLay extends Overlay {
	private GeoPoint gp1;
	private String status;

	public MyOverLay(GeoPoint gp1) {
		this.gp1 = gp1;
	}

	public MyOverLay(GeoPoint gp1, String status) {
		this.gp1 = gp1;
		this.status = status;
	}

	@Override
	public boolean draw(Canvas canvas, MapView mapView, boolean shadow,
			long when) {
		Projection projection = mapView.getProjection();
		if (shadow == false) {
			Paint paint = new Paint();
			paint.setAntiAlias(true);
			Point point = new Point();
			projection.toPixels(gp1, point);

			super.draw(canvas, mapView, shadow);
			// ---translate the GeoPoint to screen pixels---
			Point screenPts = new Point();
			mapView.getProjection().toPixels(gp1, screenPts);

			// ---add the marker---
			if (status.equals("mylocation")) {
				Bitmap bmp = BitmapFactory.decodeResource(
						mapView.getResources(), R.drawable.markerme);
				canvas.drawBitmap(bmp, screenPts.x - 10, screenPts.y - 34, null);
				return true;
			} else {
				Bitmap bmp = BitmapFactory.decodeResource(
						mapView.getResources(), R.drawable.marker);
				canvas.drawBitmap(bmp, screenPts.x - 10, screenPts.y - 34, null);
				return true;
			}
		}
		return super.draw(canvas, mapView, shadow, when);
	}

}
